package com.mew.slots.core.game.hlsd.service;

import com.alibaba.fastjson.JSON;
import com.mew.common.entity.game.WinFree;
import com.mew.slots.core.common.game.BaseGameService;
import com.mew.slots.core.common.game.vo.BasePlayMsgs;
import com.mew.slots.core.common.messge.response.SlotsPlayResponseMessage;
import com.mew.slots.core.common.vo.StrategyGameVO;
import com.mew.slots.core.game.hlsd.bo.HlsdInRoom;
import com.mew.slots.core.game.hlsd.bo.HlsdPlayMsgs;
import com.mew.slots.core.game.hlsd.message.HlsdResponseMessage;
import com.mew.slots.core.game.hlsd.roller.HlsdIli;
import com.mew.slots.core.game.hlsd.roller.HlsdXml;
import com.mew.slots.core.game.hlsd.room.HlsdRoom;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author Dylin
 */
@Service
@Slf4j
public class HlsdService extends BaseGameService {
    @Override
    public BasePlayMsgs startGame(StrategyGameVO player) {
        HlsdRoom room = new HlsdRoom();
        room.init(player.getRollerId(), HlsdIli.getInstance(),player.getWinFree().getFrees()>0,player.getInBetNumber(),player.getControlType());
        room.roundPlayIli();
        BasePlayMsgs res = room.getRes();
        if(res.getBouns()>0){
            List<Integer> biList = new ArrayList<>();
            biList.add(4);
            biList.add(8);
            biList.add(10);
            biList.add(15);
            biList.add(20);
            biList.add(25);
            Collections.shuffle(biList);
            HlsdInRoom inRoom = new HlsdInRoom();
            inRoom.setBonusIcons(biList.stream().mapToInt(Integer::intValue).toArray());
            player.getWinFree().setJson(JSON.toJSONString(inRoom));
        }
        return res;
    }

    @Override
    public SlotsPlayResponseMessage myResp(WinFree winFree, BasePlayMsgs res) {
        HlsdResponseMessage message = new HlsdResponseMessage();
        HlsdPlayMsgs pmres = (HlsdPlayMsgs) res;
        message.setBonus(pmres.getBouns());
        message.setChangeWilds(pmres.getChangeWilds());
        if(pmres.getBouns() > 0){
            winFree.setBounsType(pmres.getBouns());
            winFree.setBounsNumber(pmres.getBouns() == 1 ? 3 : 1);
        }
        return message;
    }
    @Override
    public void myAfterResp(SlotsPlayResponseMessage message,StrategyGameVO player, BasePlayMsgs res) { }
}
